package com.better.frontend.controller.suggest;

import com.better.common.base.ServiceResponse;
import com.better.common.utils.ServiceResponseHandle;
import com.better.common.utils.SessionUtils;
import com.better.frontend.Iservice.suggest.UserSuggestService;
import com.better.frontend.domain.suggest.UserSuggest;
import com.better.frontend.model.suggest.UserSuggestParam;
import com.better.frontend.model.base.ValidationGroupSave;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2018/1/24.
 * 用户使用建议
 */
@RestController
@RequestMapping("api/suggest")
@Api(value = "用户建议反馈管理", tags = {"用户建议反馈管理接口"})
public class UserSuggestController {
    @Autowired
    private UserSuggestService userSuggestService;

    @PostMapping("/save")
    @ApiOperation(value = "建议", notes = "建议")
    public ServiceResponse<UserSuggest> save(@RequestBody @Validated({ValidationGroupSave.class}) UserSuggestParam userSuggestParam) {
        UserSuggest userSuggest=new UserSuggest();
        BeanUtils.copyProperties(userSuggestParam,userSuggest);
        userSuggest.setUserId(SessionUtils.getUserInfo().getId());
        userSuggest.setUserName(SessionUtils.getUserInfo().getName());
        userSuggest.setSchoolId(SessionUtils.getUserInfo().getSchoolId());
        userSuggest.setSchoolName(SessionUtils.getUserInfo().getSchoolName());
        return ServiceResponseHandle.success(userSuggestService.save(userSuggest));
    }
    @PostMapping("/list")
    @ApiOperation(value = "获取建议", notes = "查询用户建议信息")
    public ServiceResponse<Page<UserSuggest>> findPage(@RequestBody  @Validated UserSuggestParam userSuggestParam) {
        UserSuggest userSuggest=new UserSuggest();
        BeanUtils.copyProperties(userSuggestParam,userSuggest);
        return ServiceResponseHandle.success(userSuggestService.findPageByCondition(userSuggest,userSuggestParam.getPageSize(),userSuggestParam.getPageIndex()));
    }
}
